<?php 
/**
 * Description of form
 * @author diotheos
 * @since 7 мая 2010
 */
class App_Form_Search_Simple extends Lib_Form_Clear{
	/**
	 * Initialization of form function
	 * 
	 * @since 7 мая 2010
	 * @author diotheos
	 * @return Zend_Form
	 */
	public function init(){
		
/* Initialization section
 **************************************************************************************************/		
        parent::init();
        $this->setMethod('get');
        $this->setAction('search');
        $this->setAttrib('class','search-widget');
        
        
        
/* General section
 **************************************************************************************************/
        $category = new Zend_Form_Element_Hidden('category');
        $this->addElement($category);
        
        $generalSet = new Zend_Form_SubForm();
        $general = new Zend_Form_SubForm();
        
        $general->addElements(array(
            new Zend_Form_Element_Select('mark',array(
                    'label'=>_('Марка'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'mark-model[0]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('model',array(
                    'label'=>_('Модель'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'mark-model[0]',
                    'class' => 'styled'
            ))
        ));
        
        $generalSet->addSubForm($general,'0',1);
        $this->addSubForm($generalSet,'general',10);
        
/* Year section
 **************************************************************************************************/
        $year = new Zend_Form_SubForm();
        $year->setLegend(_('Год выпуска'));
        $year->addElements(array(
            new Zend_Form_Element_Select('from',array(
                    'label'=>_('От'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[year]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('to',array(
                    'label'=>_('До'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[year]',
            		'class' => 'styled'
                    
            ))
        ));
//        $year->setAttrib('class', 'hide-labels');
        
        $this->addSubForm($year,'year', 20);
        
/* Price section
 **************************************************************************************************/
        $price = new Zend_Form_SubForm();
        $price->setLegend(_('Цена'));
        $price->addElements(array(
            new Zend_Form_Element_Text('from',array(
                    'label'=>_('От'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[price]',
                    
            )),
            new Zend_Form_Element_Text('to',array(
                    'label'=>_('До'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[price]',
                    
            )),
            new Zend_Form_Element_Select('currency', array(
                	'label'=>'',
                    'decorators' => array('ViewHelper'),
            		'belongsTo' => 'params[price]',
                    'class' => 'styled'
            ))
	    ));
        $this->addSubForm($price,'price', 30);

/* Placement section
 **************************************************************************************************/
        $placementSet = new Zend_Form_SubForm();
        $placement = new Zend_Form_SubForm();

        $placement->addElements(array(
            new Zend_Form_Element_Select('state',array(
                    'label'=>_('Область'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'state-city[0]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('city',array(
                    'label'=>_('Город'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'state-city[0]',
                    'class' => 'styled'
                    
            ))
        ));
        
        $placementSet->addSubForm($placement,0);
        $this->addSubForm($placementSet,'placement', 50);
        
        
        $photoCount = new Zend_Form_Element_Checkbox('photo_count');
        $photoCount->setLabel( _('Только с фото'));
        $photoCount->setBelongsTo('params');
        $this->addElement($photoCount);

        $submit  = new Zend_Form_Element_Submit('search');
        $submit->setOptions(array(
            'order'=>990,
            'label'=>_('Поиск'),
            
        ));
        $this->addElement($submit);
	      
        $this->setDecorators(array(
            array('ViewScript', array('viewScript'=>'forms/search/simple.phtml', 'class'=> 'form element'))
        ));
        
		return $this;
	}
}